import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service: 服务器上传配置
 * @date: 2019-7-5
 */
import request from 'utils/request';
import { CPAAS_FILE } from 'utils/config';
import { getCurrentOrganizationId, isTenantRoleLevel } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
/**
 * 查询列表
 * @async
 * @function queryConfig
 * @param {Object} params - 查询参数
 */

export function queryConfig(_x) {
  return _queryConfig.apply(this, arguments);
}
/**
 * 获取配置明细
 * @async
 * @function fetchConfigDetail
 * @param {Object} params - 查询参数
 */

function _queryConfig() {
  _queryConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "server-configs"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _queryConfig.apply(this, arguments);
}

export function fetchConfigDetail(_x2) {
  return _fetchConfigDetail.apply(this, arguments);
}
/**
 * 创建配置
 * @async
 * @function createConfig
 * @param {Object} params - 查询参数
 */

function _fetchConfigDetail() {
  _fetchConfigDetail = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    var configId;
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            configId = params.configId;
            return _context2.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "server-configs/").concat(configId), {
              method: 'GET'
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchConfigDetail.apply(this, arguments);
}

export function createConfig(_x3) {
  return _createConfig.apply(this, arguments);
}
/**
 * 保存配置
 * @async
 * @function saveConfig
 * @param {Object} params - 查询参数
 */

function _createConfig() {
  _createConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "server-configs"), {
              method: 'POST',
              body: params
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _createConfig.apply(this, arguments);
}

export function saveConfig(_x4) {
  return _saveConfig.apply(this, arguments);
}

function _saveConfig() {
  _saveConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_FILE, "/v1/").concat(isTenantRoleLevel() ? "".concat(organizationId, "/") : '', "server-configs"), {
              method: 'PUT',
              body: params
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _saveConfig.apply(this, arguments);
}